package com.stox.ui.javafx.list.widget.menu.item;

import java.util.Locale;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.stox.dto.AbstractModel;
import com.stox.ui.javafx.list.widget.menu.WatchListContextMenu;

@Component
public class RenameWatchListMenuItem extends MenuItem implements
		InitializingBean, EventHandler<ActionEvent> {

	@Autowired
	private ApplicationContext applicationContext;
	
	public RenameWatchListMenuItem() {
		setOnAction(this);
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		setText(applicationContext.getMessage("Rename", null, Locale.getDefault()));
	}
	
	@Override
	public void handle(ActionEvent arg0) {
		WatchListContextMenu watchListContextMenu = (WatchListContextMenu)getParentPopup(); 
		TreeView<AbstractModel> treeView = watchListContextMenu.getTreeView();
		TreeItem<AbstractModel> treeItem = treeView.getSelectionModel().getSelectedItem();
		treeView.edit(treeItem);
	}

}
